package com.tanovo.secure;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.tanovo.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

//@Component
@Slf4j
public class ErrorFilter extends ZuulFilter {

    @Override
    public Object run() {
        log.info("==============zuul网关error拦截器==============");
        RequestContext ctx = RequestContext.getCurrentContext();
        Throwable throwable = ctx.getThrowable();
        Throwable cause = throwable.getCause();
        log.info("==============zuul网关error拦截器,异常：",cause);
        if(cause instanceof ServiceException){
            log.error("业务异常:{}",cause.getMessage());
        }else {
            log.error("系统异常:{}",cause.getMessage());
        }
        return null;
    }


    @Override
    public String filterType() {
        return "error";
    }

    @Override
    public int filterOrder() {
        return 3;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

}
